//package cn.bugstack.xfg.dev.tech.oauth.config;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
//@Configuration
//@EnableWebSecurity
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//    /**
//     * 加密算法
//     */
//    @Bean
//    PasswordEncoder passwordEncoder() {
//        return new BCryptPasswordEncoder();
//    }
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        //todo 允许表单登录
//
///*
//       ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http.authorizeRequests();
//       registry.antMatchers("/oauth/**").permitAll();
//       http.authorizeRequests()
//               .antMatchers("/login","/oauth/**","/oauth/login/**").permitAll()
//               .anyRequest().authenticated()
//               .and()
//               .formLogin()
//               .loginPage("/oauth/login")
//               .loginProcessingUrl("/login")
//               .permitAll()
//               .and()
//             .csrf()
//               .disable();*/
//
////        http
////                .authorizeRequests()
////                .antMatchers("/login", "/oauth/**", "/oauth/login/**").permitAll()
////                .anyRequest().authenticated()
////                .and()
////                .formLogin()
////                .loginPage("/oauth/login")
////                .loginProcessingUrl("/login")
////                .permitAll()
////                .and()
////                .csrf().disable()
////                .headers().frameOptions().disable() // 如果需要iframe
////                .and()
////                .httpBasic().disable()
////                .logout().permitAll();
//    }
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        //从内存中加载用户，实际生产中需要从数据库中加载
//        auth.inMemoryAuthentication()
//                .withUser("admin")
//                .password(new BCryptPasswordEncoder().encode("123456"))
//                .roles("admin");//后面可以跟and连接
//    }
//    /**
//     * AuthenticationManager对象在OAuth2认证服务中要使用，提前放入IOC容器中
//     * Oauth的密码模式需要
//     */
//    @Override
//    @Bean
//    public AuthenticationManager authenticationManagerBean() throws Exception {
//        return super.authenticationManagerBean();
//    }
//}